﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Generator
{
    public class OpenersClosers
    {
        public List<int> Openers { get; private set; }

        public List<int> Closers { get; private set; }

        public OpenersClosers()
        {
            Openers = new List<int>();
            Closers = new List<int>();
        }

        public void AddOpener(int pID)
        {
            Openers.Add(pID);
        }

        public void AddCloser(int pID)
        {
            Closers.Add(pID);
        }

        public int FindCommon(OpenersClosers pPrevious)
        {
            var common = from guyId in pPrevious.Closers
                         where Openers.Contains(guyId)
                         select guyId;
            if (common.Any())
            {
                return common.First();
            }
            return -1;
        }
    }
}
